<template>
  <div>
    <div>
      <el-button type="primary" @click="toFormHandler">新增</el-button>
      <el-table :data="interface" style="width: 100%">
        <el-table-column prop="name" label="应用名称" width="180">
        </el-table-column>
        <el-table-column prop="status" label="状态" width="180">
        </el-table-column>
        <el-table-column prop="url" label="url"> </el-table-column>
        <el-table-column width="100" align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="editHandler(scope.row)"
              >修改</el-button
            >
            <el-button type="text" @click="deleteHandler(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { del, get } from "@/utils/request";
export default {
  data() {
    return {
      interface: [],
      visible: false
    };
  },
  methods: {
    loadInterface() {
      let url = "http://120.77.41.127:8888/interfaces/query";
      get(url).then(resp => {
        this.interface = resp.data;
      });
    },
    toFormHandler() {
      this.$router.push({ path: "/ldd/Interface_Form" });
    },
    editHandler(row) {
      this.$router.push({
        path: "/ldd/Interface_Form",
        query: row
      });
    },
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let url = "http://120.77.41.127:8888/interfaces/deleteById";
        del(url, { id: row.id }).then(resp => {
          // 1. 提示
          this.$message({ type: "success", message: resp.message });
          // 2. 刷新
          this.loadInterface();
        });
      });
    }
  },
  created() {
    this.loadInterface();
  }
};
</script>

<style lang="sass" scoped>

</style>
